package reflect;

import com.sun.org.apache.xpath.internal.operations.Mod;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ResourceBundle;

/**
 * 反编译constructor
 */

public class ReflectTest11 {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException {

        Class c = Class.forName(ResourceBundle.getBundle("classinfo2").getString("className"));
        Object obj = c.newInstance();
        StringBuilder s = new StringBuilder();
        //public class User {
        s.append(Modifier.toString(c.getModifiers()));
        s.append(" class ");
        s.append(c.getSimpleName());
        s.append("{\n");


        //p拼接构造方法
        Constructor[] constructors = c.getDeclaredConstructors();
        for (Constructor constructor:constructors){
            s.append("\t");
            //public User(String name) {
            s.append(Modifier.toString(constructor.getModifiers()));
            s.append(" ");
            s.append(c.getSimpleName());
            s.append("(");

            //参数
            Class[] paras = constructor.getParameterTypes();
            for (Class para:paras){
                s.append(para.getSimpleName());
                s.append(",");
            }
            //如果直接删除，在没有参数的构造函数时 就会把（ 删掉
            //不要用null来判断
            if (paras.length >0){
                s.deleteCharAt(s.length()-1);
            }

            s.append("){}\n");
        }

        s.append("}");

        Constructor method = c.getConstructor();

        System.out.println(s);





    }
}
